package org.example.rubbish.common;

import java.util.List;

public class PageResult<T> {
    private Integer current;
    private Integer size;
    private Long total;
    private List<T> records;
    private Integer pages;

    // 构造方法
    public PageResult() {}

    public PageResult(Integer current, Integer size, Long total, List<T> records) {
        this.current = current;
        this.size = size;
        this.total = total;
        this.records = records;
        this.pages = (int) Math.ceil((double) total / size);
    }

    // 静态 success 方法
    public static <T> PageResult<T> success(List<T> records, Long total) {
        return new PageResult<>(1, records.size(), total, records);
    }

    public static <T> PageResult<T> success(Integer current, Integer size, Long total, List<T> records) {
        return new PageResult<>(current, size, total, records);
    }

    public Integer getCurrent() {
        return current;
    }

    public void setCurrent(Integer current) {
        this.current = current;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List<T> getRecords() {
        return records;
    }

    public void setRecords(List<T> records) {
        this.records = records;
    }

    public Integer getPages() {
        return pages;
    }

    public void setPages(Integer pages) {
        this.pages = pages;
    }
}